package com.jp.knowledge.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.activity.ProductInterfaceActivity;
import com.jp.knowledge.model.ProductVersion;
import com.jp.knowledge.util.ImageLoadUtil;

import java.util.List;

/**
 * Created by jiayen on 17/6/12.
 */

public class ProductDetailAdapter extends  JpBaseRecyViewAdapter {

    private int action;
    public ProductDetailAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    public int getLayoutId() {
        return R.layout.product_detail_item;
    }

    public void setAction(int action) {
        this.action = action;
    }

    @Override
    public void bindViewHold(JPRecycleViewHolder holder, int position) {
        ProductVersion versionBean = (ProductVersion) getItem(position);
        TextView   version = holder.getView(R.id.version);
        TextView time = holder.getView(R.id.time);
        ImageView icon = holder.getView(R.id.icon);
        TextView name  = holder.getView(R.id.name);
        TextView  content = holder.getView(R.id.content);
        TextView  btn = holder.getView(R.id.btn);

        version.setText(versionBean.getVersion());
        time.setText(versionBean.getCreatetime());
        ImageLoadUtil.loadrund(mContext,versionBean.getIcon(),icon,1);
        name.setText(versionBean.getName());
        content.setText(versionBean.getDesc());

        btn.setTag(position);
        btn.setOnClickListener(itemClick);

        holder.getView(R.id.time).setVisibility(View.GONE);
        holder.getView(R.id.icon).setVisibility(View.GONE);
        holder.getView(R.id.name).setVisibility(View.GONE);
    }

    private View.OnClickListener  itemClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = (int) v.getTag();
            ProductVersion versionBean = (ProductVersion) getItem(position);
            Intent intent = new Intent(mContext, ProductInterfaceActivity.class);
            intent.putExtra("product_data",versionBean);
            intent.putExtra("product",true);
//            intent.putExtra("action",action);
            intent.putExtra("action",2);
            mContext.startActivity(intent);
        }
    };
}
